<template>
    <div>
        <el-table :data="peoplelist" row-key="id" :tree-props="{ children: 'children' }" border style="width: 100%">
            <el-table-column prop="id" label="角色编号" width="180" align="center">
            </el-table-column>
            <el-table-column prop="rolename" label="角色名称" align="center">
            </el-table-column>

            <el-table-column prop="status" label="状态" align="center">
                <template v-slot="item">
                    <div>
                        <el-tag v-if="item.row.status == 1" type="success">启用 </el-tag>
                        <el-tag type="danger" v-else> 禁用</el-tag>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
                <template v-slot="item">
                    <el-button type="primary" :icon="Edit" @click="edit(item.row.id)" circle />
                    <el-button type="danger" :icon="Delete" @click="del(item.row.id)" circle />
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script lang="ts" setup>
import {
    Delete,
    Edit,
} from '@element-plus/icons-vue'
import { computed } from 'vue'
import { roledelete } from '../../request/app'
// 引入仓库
import { useStore } from 'vuex'
// 兄弟传参
import emitter from '@/assets/JS/mybus'

const store = useStore()

// 派遣行动加载数据列表
async function patch() {
    await store.dispatch('setpeople/ACgetlist')
}
patch()
// 获取数据列表
const peoplelist = computed(() => store.getters["setpeople/getlist"]);

function edit(e?: any): void {
    console.log(e);
    emitter.emit('iseditId', e)
}
function del(id?: any): void {

    roledelete({
        id
    }).then(res => {
        console.log(res)
        patch()
    })

}
</script>

<style scoped>
</style>
